//update_question_answer_share_count

exports.update_question_answer_share_count = function (req, res) {

    var bodyParams = req.routeInfo.bodyParams;

    //最终结果
    var resultData = {};

    var fca_id = bodyParams.fca_id;

    //任务流创建
    async.waterfall([
            //查询分享次数
            function (cb) {
                if (fca_id) {
                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.searchContentAnswer + "/fca_id/" + fca_id,
                            method: 'POST',
                            data: {
                                fields: ['fca_id', 'fca_share_count'].join(",")
                            }
                        },
                        function (err, data) {

                            //判断是否有错误信息
                            if (err) {
                                return cb(err, data);
                            }

                            resultData.answerData = data.data;

                            cb();
                        }
                    );
                } else {
                    cb()
                }

            },
            function (cb) {
                if (resultData.answerData.length>0) {
                    var shareCount = resultData.answerData[0].fca_share_count;
                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.updateContentAnswer,
                            method: 'POST',
                            data: {
                                fca_id:fca_id,
                                fca_share_count:parseInt(shareCount)+1
                            }
                        },
                        function (err, data) {

                            //判断是否有错误信息
                            if (err) {
                                return cb(err, data);
                            }

                            resultData.updateData = data.data;

                            cb();
                        }
                    );
                } else {
                    cb()
                }

            }

        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );


}